package cn.besbing.server.service.lims;


import cn.besbing.client.enums.BaseResponse;
import cn.besbing.client.enums.StatusCode;
import cn.besbing.model.entities.primary.*;
import cn.besbing.model.mapper.primary.NcBasprodTypeMapper;
import cn.besbing.server.service.primary.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 *
 *
 /**
 **************************************************************
 *                                                            *
 *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='    *
 *    |                如果有一天我选择离开                 |    *
 *    |                  不是因为我输了                    |    *
 *    |                   是因为我懂了                     |    *
 *    |              就算我得不到曾经的尊敬                  |    *
 *    |              起码不能丢了昨天的尊严                  |    *
 *    |            每天陪些小白试些注定死的道路               |    *
 *    |                    真是闲的                       |    *
 *    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='    *
 *                because I can't see tomorrow                *
 *                          不值得                             *
 *                 Author : sheny  2021-05-11                 *
 **************************************************************
 */


//@Service
@org.springframework.stereotype.Component
public class AnalysisSync {


    @Autowired
    private PrimaryAnalysisServiceImpl analysisService;

    @Autowired
    private PrimaryProductServiceImpl productService;


    @Autowired
    private PrimaryNcAnalysisListServiceImpl ncAnalysisListService;

    @Autowired
    private PrimaryComponentServiceImpl componentService;

    @Autowired
    private CustomerSqlServiceImpl customerSqlService;

    @Autowired
    private PrimaryNcTestListServiceImpl ncTestListService;

    @Autowired
    private primaryNcBasprodNameServiceImpl ncBasprodNameService;

    @Autowired
    private PrimaryNcBasprodTypeServiceImpl ncBasprodTypeService;

    @Autowired
    private PrimaryNcBasprodPointServiceImpl ncBasprodPointService;

    @Autowired
    private PrimaryNcProdListServiceImpl ncProdListService;

    @Autowired
    private PrimaryNcBasprodStructServiceImpl ncBasprodStructService;

    @Autowired
    private PrimaryNcBasProdContactServiceImpl ncBasProdContactService;

    @Autowired
    private PrimaryNcBasprodTempServiceImpl ncBasprodTempService;

    @Autowired
    private PrimaryNcSampleInfoServiceImpl ncSampleInfoService;

    @Autowired
    private PrimaryNcTestInitServiceImpl ncTestInitService;

    @Autowired
    private PrimaryNcTaskAddunionServiceImpl ncTaskAddunionService;

    @Autowired
    private PrimaryNcTestlistCompServiceImpl ncTestlistCompService;

    @Autowired
    private PrimaryNcTestAfterServiceImpl ncTestAfterService;

    @Autowired
    private PrimaryNcBasEnType ncBasEnType;


    BaseResponse baseResponse = new BaseResponse(StatusCode.SUCCESS);

    Logger logger = LoggerFactory.getLogger(this.getClass());

    NcBasprodPoint ncBasprodPoint = null;

    NcTestlistComp ncTestlistComp = null;

    NcBasprodStruct ncBasprodStruct = null;

    NcBasprodContact ncBasprodContact = null;

    NcProdListKey ncProdListKey = null;

    NcProdList ncProdList = null;

    NcTestList ncTestList = null;

    NcBasprodName ncBasprodName = null;

    NcTaskAddunion ncTaskAddunion = null;

    NcBasprodType ncBasprodType = null;

    NcBasenType ncBasenType = null;

    NcBasprodTemp ncBasprodTemp = null;

    NcSampleInfo ncSampleInfo = null;

    NcTestInit ncTestInit = null;

    NcTestAfter ncTestAfter = null;


    String executeSql = "";

    List<String> pkBasprodPoint = new ArrayList<>();

    List<String> pkBasprodStruct = new ArrayList<>();

    List<String> pkBasprodTemp = new ArrayList<>();

    List<String> pkSampleInfo = new ArrayList<>();

    /*********所有分析同步************************************/

    public BaseResponse setAllAnalysisSyncThread(){

        return baseResponse;
    }

    /*********分析同步结束************************************/


/*------------------------------------------------------------------------------------------------------------------*/


    /*********所有product同步********************************/

    public BaseResponse setAllProductSyncThread(){

        return baseResponse;
    }

    /*********product同步结束********************************/


/*------------------------------------------------------------------------------------------------------------------*/


    /*********单个分析同步************************************/
    /*@
    jsonStr:
    jsonStr.getString("analysis")
    jsonStr.getString("version")
     */
    public BaseResponse setAnalysisSyncThread(JSONObject jsonStr){
        Analysis analysis = analysisService.getAnalysisByPrimarykey(jsonStr);
        NcAnalysisList ncAnalysisList = null;
        ncAnalysisList = new NcAnalysisList();
        ComponentKey componentKey = null;
        NcComponentTable ncComponentTableKey = null;
        List<Component> componentList = null;
        String componentSql = "";
        String exist = "";

        if (analysis != null){
            ncAnalysisList.setName(analysis.getName());
            ncAnalysisList.setVersion(analysis.getVersion());
        }else {
            return baseResponse = new BaseResponse(700,"没查询到分析，程序中止");
        }
        //查询分析名和版本组合主键是不是已经在nc_analysis_list表中
        if (ncAnalysisListService.selectNcAnalysisListByAnalysisAndVersion(ncAnalysisList)){
            return baseResponse = new BaseResponse(700,"有重复分析，程序中止");
        }
        //如果是试验前参数
        if("试验前参数".equals(analysis.getcTestType().trim())){
            componentKey = new ComponentKey();
            ncComponentTableKey = new NcComponentTable();
            componentList = new ArrayList<>();
            componentKey.setAnalysis(analysis.getName());
            componentKey.setVersion(analysis.getVersion());
            componentList = componentService.selectByTS(componentKey);
            for (Component c : componentList){
                ncComponentTableKey.setAnalysis(c.getAnalysis().trim());
                ncComponentTableKey.setName(c.getName().trim());
                ncComponentTableKey.setNcComponentName(c.getName().trim());
                ncComponentTableKey.setVersion(Long.valueOf(c.getVersion().toString().trim()));
                exist =customerSqlService.selectOne("select 1 from nc_component_table where NC_COMPONENT_NAME = '" +
                        c.getName().trim() + "' and ANALYSIS = '" + c.getAnalysis().trim() + "' and NAME = '" +
                        c.getName() + "' and VERSION = " + c.getVersion());
                if (exist == null || "".equals(exist) || exist == ""){
                    //如果不存在该参数，则开始添加
                    componentSql = customerSqlService.selectOne(" select sql_text from sql_records where sql_code like 'analysis4' ");
                    componentSql = componentSql.replace("sheny",c.getAnalysis());
                    componentSql = componentSql.replace("why",String.valueOf(c.getVersion()));
                    componentSql = componentSql.replace("dataloader",c.getName());
                    customerSqlService.insert(componentSql);
                }
            }
        }
        //如果是试验后参数
        if("试验后参数".equals(analysis.getcTestType().trim())){
            componentKey = new ComponentKey();
            ncComponentTableKey = new NcComponentTable();
            componentList = new ArrayList<>();
            componentKey.setAnalysis(analysis.getName());
            componentKey.setVersion(analysis.getVersion());
            componentList = componentService.selectByTS(componentKey);
            for (Component c : componentList){
                ncComponentTableKey.setAnalysis(c.getAnalysis().trim());
                ncComponentTableKey.setName(c.getName().trim());
                ncComponentTableKey.setNcComponentName(c.getName().trim());
                ncComponentTableKey.setVersion(Long.valueOf(c.getVersion().toString().trim()));
                exist =customerSqlService.selectOne("select 1 from nc_component_table where NC_COMPONENT_NAME = '" +
                        c.getName().trim() + "' and ANALYSIS = '" + c.getAnalysis().trim() + "' and NAME = '" +
                        c.getName() + "' and VERSION = " + c.getVersion());
                if (exist == null || "".equals(exist) || exist == ""){
                    //如果不存在该参数，则开始添加
                    componentSql = customerSqlService.selectOne(" select sql_text from sql_records where sql_code like 'analysis4' ");
                    componentSql = componentSql.replace("sheny",c.getAnalysis());
                    componentSql = componentSql.replace("why",String.valueOf(c.getVersion()));
                    componentSql = componentSql.replace("dataloader",c.getName());
                    customerSqlService.insert(componentSql);
                }
            }
        }
        //如果是正常条件
        if("测试条件".equals(analysis.getcTestType().trim()) && ncAnalysisListService.selectNcAnalysisListByAnalysisAndVersion(ncAnalysisList) == false){
            logger.info("开始查询添加测试条件...........");
            List<String> addAnalysisSqls = customerSqlService.selectAsList("select sql_text from sql_records where sql_code like 'analysis%' ");
            logger.info("结束查询添加测试条件...........");
            for (String analysisSql : addAnalysisSqls){
                //逐条插入分析，每个分析三条语句
                analysisSql = analysisSql.replace("sheny",analysis.getName());
                analysisSql = analysisSql.replace("why",String.valueOf(analysis.getVersion()));
                try{
                    logger.info("开始执行语句{}..........",analysisSql);
                    customerSqlService.insert(analysisSql);
                    logger.info("结束执行语句{}..........",analysisSql);
                }catch (Exception e) {
                    logger.error("分析添加错误...语句：{}", analysisSql);
                }
            }
        }
        //如果是正常结果
        if("测试结果".equals(analysis.getcTestType().trim()) && ncAnalysisListService.selectNcAnalysisListByAnalysisAndVersion(ncAnalysisList) == false){
            logger.info("开始查询添加测试结果...........");
            List<String> addAnalysisSqls = customerSqlService.selectAsList("select sql_text from sql_records where sql_code like 'analysis%' ");
            logger.info("结束查询添加测试结果...........");
            for (String analysisSql : addAnalysisSqls){
                //逐条插入分析，每个分析三条语句
                analysisSql = analysisSql.replace("sheny",analysis.getName());
                analysisSql = analysisSql.replace("why",String.valueOf(analysis.getVersion()));
                try{
                    logger.info("开始执行语句{}..........",analysisSql);
                    customerSqlService.insert(analysisSql);
                    logger.info("结束执行语句{}..........",analysisSql);
                }catch (Exception e) {
                    logger.error("分析添加错误...语句：{}", analysisSql);
                }
            }
        }
        return baseResponse;
    }

    /*********分析同步结束************************************/

/*------------------------------------------------------------------------------------------------------------------*/


    /********单个product同步********************************/

    /*@
    jsonStr:
    jsonStr.getString("product")
    jsonStr.getString("version")
    jsonStr.getString("testlist")
     */
    public BaseResponse setProductSyncThread(JSONObject jsonStr) throws Exception {
        /**
         * 通用变量定义
         */
        String productName = "";
        String productCode = "";
        String productTestlist = "";
        String productVersion = "";


        //获取前端传来的product，判断在product里是否存在
        Product product = new Product();
        product = getProduct(jsonStr);
        if(product == null){
            baseResponse = new BaseResponse(700,"没查询到product，请检查product名称及版本，程序中止");
            throw new Exception(JSON.toJSONString(baseResponse.getMsg()));
        }else{
            return checkProduct(product);
        }
        //校验product
        //baseResponse = checkProduct(product);
        //return baseResponse;
    }

    /*********product同步结束********************************/

    /*******************************************通用方法*****************************************************/
    private Product getProduct(JSONObject jsonProduct){
        return productService.getProductByPrimary(jsonProduct.getString("name"),jsonProduct.getLong("version"));
    }

    /**
     * 清失败的内容
     * @param ncProdListExt
     * @param ncBasenTypeExt
     */
    public void deleteProduct(NcProdList ncProdListExt,NcBasenType ncBasenTypeExt){
        String sql = "delete from nc_prod_list where trim(nc_prod_list.nc_prod_name) = '" + ncProdListExt.getNcProdName() + "' ";
        customerSqlService.delete(sql);
        if (ncBasenTypeExt != null && ncBasenTypeExt.getPkBasenType() != null && !"".equals(ncBasenTypeExt.getPkBasenType())){
            sql = "delete from NC_BASEN_TYPE nt where nt.pk_basen_type in ('" + ncBasenTypeExt.getPkBasenType() + "')";
            customerSqlService.delete(sql);
        }
    }

    @Transactional
    public BaseResponse checkProduct(Product product) throws Exception{
        /**
         * 判断nc_prod_list表是否存在
         * 首先判断是不是已经存在，存在的话抛错回去
         * 不在的话，开始准备校验
         */
        BaseResponse baseResponseArea = new BaseResponse(StatusCode.SUCCESS);
        JSONObject transJson = new JSONObject();

        if (checkNcProdListExist(product)){
            //return baseResponse = new BaseResponse(700,"该product及版本已经存在于NC_PROD_LIST中，程序中止");
            return baseResponse = new BaseResponse(700,"该product及版本已经存在于NC_PROD_LIST中，程序中止");
            //throw new Exception(transJson.toJSONString(baseResponse));
        }

        logger.info("开始校验并写入方法模板，如返回700则直接rollback并在前台抛错..........");
        baseResponseArea = checkNcProdList(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcTestList(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasProdName(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasProdType(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasEnType(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasprodPoint(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasprodStruct(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasprodContact(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcBasprodTemp(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcSampleInfo(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcTestInfo(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcTaskAddunion(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcTestListComp(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        baseResponseArea = checkNcTestAfter(product);
        if (baseResponseArea.getCode() == 700 ){
            //throw new Exception(JSON.toJSONString(baseResponseArea));
            deleteProduct(ncProdList,ncBasenType);
            return baseResponseArea;
        }
        logger.info("方法模板{}写入成功.........",product.getName());
        return baseResponse;
    }

    /**
     * fuck PM
     * 你大爷
     * @param product
     * @return
     */
    public BaseResponse checkNcTestAfter(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncTestAfter = new NcTestAfter();
        executeSql = getExecuteSql("testlist_nc_test_after",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_test_after取数据为空或存在多条同名称同版本数据");
        }

         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncTestAfter = new NcTestAfter();
                ncTestAfter.setPkTestAfter(map.get("PK_TEST_AFTER").toString());
                ncTestAfter.setPkResultType(map.get("PK_RESULT_TYPE").toString());
                ncTestAfter.setPkUnitsType(map.get("PK_UNITS_TYPE").toString());
                ncTestAfter.setTestAfterCode(map.get("TEST_AFTER_CODE").toString());
                ncTestAfter.setTestAfterName(map.get("TEST_AFTER_NAME").toString());
                ncTestAfter.setNcEnstard(map.get("NC_ENSTARD").toString());
                ncTestAfter.setNcEntry(Long.valueOf(map.get("NC_ENTRY").toString()));
                ncTestAfter.setNcAnalysisName(map.get("NC_ANALYSIS_NAME").toString());
                ncTestAfter.setNcAnalysisVersion(Long.valueOf(map.get("NC_ANALYSIS_VERSION").toString()));
                ncTestAfter.setNcAnalysisType(map.get("NC_ANALYSIS_TYPE").toString());
                ncTestAfter.setNcSpecRule(map.get("NC_SPEC_RULE").toString());
                ncTestAfter.setNcMinValue(map.get("NC_MIN_VALUE").toString());
                ncTestAfter.setNcMaxValue(map.get("NC_MAX_VALUE").toString());
                ncTestAfter.setNcTextValue(map.get("NC_TEXT_VALUE").toString());
                ncTestAfter.setNcStage(map.get("NC_STAGE").toString());
                ncTestAfter.setNcSamplePoint(map.get("NC_SAMPLE_POINT").toString());
                ncTestAfter.setNcContactType(map.get("NC_CONTACT_TYPE").toString());
                ncTestAfter.setNcCoilType(map.get("NC_COIL_TYPE").toString());
                ncTestAfter.setNcCoilCurrent(map.get("NC_COIL_CURRENT").toString());
                ncTestAfter.setDef1(map.get("DEF1").toString());
                ncTestAfter.setDef2(map.get("DEF2").toString());
                ncTestAfter.setDef3(map.get("DEF3").toString());
                ncTestAfter.setDef4(map.get("DEF4").toString());
                ncTestAfter.setDef5(map.get("DEF5").toString());
                ncTestAfterService.insert(ncTestAfter);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_test_after组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcTestListComp(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncTestlistComp = new NcTestlistComp();
        executeSql = getExecuteSql("testlist_nc_testlist_comp",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_testlist_comp取数据为空或存在多条同名称同版本数据");
        }

         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncTestlistComp = new NcTestlistComp();
                ncTestlistComp.setPkTestlistComp(map.get("PK_TESTLIST_COMP").toString());
                ncTestlistComp.setPkUnitsType(map.get("PK_UNITS_TYPE").toString());
                ncTestlistComp.setPkListTable(map.get("PK_LIST_TABLE").toString());
                ncTestlistComp.setNcTestcompCode(map.get("NC_TESTCOMP_CODE").toString());
                ncTestlistComp.setNcTestcompName(map.get("NC_TESTCOMP_NAME").toString());
                ncTestlistComp.setNcTestlistName(map.get("NC_TESTLIST_NAME").toString());
                ncTestlistComp.setNcAnalysisName(map.get("NC_ANALYSIS_NAME").toString());
                ncTestlistComp.setNcTlcComponent(map.get("NC_TLC_COMPONENT").toString());
                ncTestlistComp.setAnalysisCount(map.get("ANALYSIS_COUNT").toString());
                ncTestlistComp.setOrderNumber(map.get("ORDER_NUMBER").toString());
                ncTestlistComp.setResultOrderNo(map.get("RESULT_ORDER_NO").toString());
                ncTestlistComp.setUnits(map.get("UNITS").toString());
                ncTestlistComp.setRound(map.get("ROUND").toString());
                ncTestlistComp.setPlaces(Long.valueOf(map.get("PLACES").toString()));
                ncTestlistComp.setReplicateCount(Long.valueOf(map.get("REPLICATE_COUNT").toString()));
                ncTestlistComp.setMinLimit(BigDecimal.valueOf(Long.valueOf(map.get("MIN_LIMIT").toString())));
                ncTestlistComp.setMaxLimit(BigDecimal.valueOf(Long.valueOf(map.get("MAX_LIMIT").toString())));
                ncTestlistComp.setReportable(map.get("REPORTABLE").toString());
                ncTestlistComp.setOptional(map.get("OPTIONAL").toString());
                ncTestlistComp.setDisplayed(map.get("DISPLAYED").toString());
                ncTestlistComp.setFactorValues(map.get("FACTOR_VALUES").toString());
                ncTestlistComp.setAnalysisVersion(Long.valueOf(map.get("ANALYSIS_VERSION").toString()));
                ncTestlistComp.setcDefaultValue(map.get("C_DEFAULT_VALUE").toString());
                ncTestlistComp.setcEnDefaultValue(map.get("C_EN_DEFAULT_VALUE").toString());
                ncTestlistComp.setListKey(map.get("LIST_KEY").toString());
                ncTestlistComp.setcDefaultDbFile(Long.valueOf(map.get("C_DEFAULT_DB_FILE").toString()));
                ncTestlistCompService.insert(ncTestlistComp);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_testlist_comp组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcTaskAddunion(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncTaskAddunion = new NcTaskAddunion();
        executeSql = getExecuteSql("testlist_nc_task_addunion",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_task_addunion取数据为空或存在多条同名称同版本数据");
        }

         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncTaskAddunion = new NcTaskAddunion();
                ncTaskAddunion.setPkTaskAddunion(map.get("PK_TASK_ADDUNION") == null?"-":map.get("PK_TASK_ADDUNION").toString());
                ncTaskAddunion.setNcTaskAddcode(map.get("NC_TASK_ADDCODE").toString());
                ncTaskAddunion.setNcTaskAddname(map.get("NC_TASK_ADDNAME").toString());
                ncTaskAddunion.setNcTestlistName(map.get("NC_TESTLIST_NAME").toString());
                ncTaskAddunion.setNcAnalysisMethod(map.get("NC_ANALYSIS_METHOD").toString());
                ncTaskAddunion.setNcReportName(map.get("NC_REPORT_NAME").toString());
                ncTaskAddunion.setNcTaskType(map.get("NC_TASK_TYPE").toString());
                ncTaskAddunion.setNcTaskDes(map.get("NC_TASK_DES").toString());
                ncTaskAddunion.setNcTaskName(map.get("NC_TASK_NAME").toString());
                ncTaskAddunion.setNcIncludeProtype(map.get("NC_INCLUDE_PROTYPE").toString());
                ncTaskAddunion.setNcCbPlan(map.get("NC_CB_PLAN").toString());
                ncTaskAddunion.setNcOrderNumber(Long.valueOf(map.get("NC_ORDER_NUMBER").toString()));
                ncTaskAddunion.setDef1(map.get("DEF1").toString());
                ncTaskAddunion.setDef2(map.get("DEF2").toString());
                ncTaskAddunion.setDef3(map.get("DEF3").toString());
                ncTaskAddunion.setDef4(map.get("DEF4").toString());
                ncTaskAddunion.setDef5(" ");
                ncTaskAddunionService.insert(ncTaskAddunion);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_task_addunion组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcTestInfo(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncTestInit = new NcTestInit();
        executeSql = getExecuteSql("testlist_nc_test_init",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_test_init取数据为空或存在多条同名称同版本数据");
        }
         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncTestInit = new NcTestInit();
                ncTestInit.setPkTestInit(map.get("PK_TEST_INIT").toString());
                ncTestInit.setPkResultType(map.get("PK_RESULT_TYPE").toString());
                ncTestInit.setPkUnitsType(map.get("PK_UNITS_TYPE").toString());
                ncTestInit.setTestInitCode(map.get("TEST_INIT_CODE").toString());
                ncTestInit.setTestInitName(map.get("TEST_INIT_NAME").toString());
                ncTestInit.setNcEnstard(map.get("NC_ENSTARD").toString());
                ncTestInit.setNcEntry(Long.valueOf(map.get("NC_ENTRY").toString()));
                ncTestInit.setNcAnalysisName(map.get("NC_ANALYSIS_NAME").toString());
                ncTestInit.setNcAnalysisVersion(Long.valueOf(map.get("NC_ANALYSIS_VERSION").toString()));
                ncTestInit.setNcAnalysisType(map.get("NC_ANALYSIS_TYPE").toString());
                ncTestInit.setNcSpecRule(map.get("NC_SPEC_RULE").toString());
                ncTestInit.setNcMinValue(map.get("NC_MIN_VALUE").toString());
                ncTestInit.setNcMaxValue(map.get("NC_MAX_VALUE").toString());
                ncTestInit.setNcTextValue(map.get("NC_TEXT_VALUE").toString());
                ncTestInit.setNcStage(map.get("NC_STAGE").toString());
                ncTestInit.setNcSamplePoint(map.get("NC_SAMPLE_POINT").toString());
                ncTestInit.setNcContactType(map.get("NC_CONTACT_TYPE").toString());
                ncTestInit.setNcCoilType(map.get("NC_COIL_TYPE").toString());
                ncTestInit.setNcCoilCurrent(map.get("NC_COIL_CURRENT").toString());
                ncTestInit.setDef1(map.get("DEF1").toString());
                ncTestInit.setDef2(map.get("DEF2").toString());
                ncTestInit.setDef3(map.get("DEF3").toString());
                ncTestInit.setDef4(map.get("DEF4").toString());
                ncTestInit.setDef5(map.get("DEF5").toString());
                ncTestInitService.insert(ncTestInit);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_test_init组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcSampleInfo(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        String sql1 = customerSqlService.selectOne("select sql_text from sql_records where sql_code = 'testlist_nc_sample_info1'");
        String sql2 = customerSqlService.selectOne("select sql_text from sql_records where sql_code = 'testlist_nc_sample_info2'");
        executeSql = sql1 + sql2;
        executeSql = executeSql.replace("prosheny",product.getName());
        executeSql = executeSql.replace("why",String.valueOf(product.getVersion()));
        executeSql = executeSql.replace("ccode",product.getCode());
        executeSql = executeSql.replace("ttestlist",product.getTestList());
        String finalSql = "";
        //数据库中语句获取完成，开始处理语句
        for(String point : pkBasprodPoint){
            for (String struct : pkBasprodStruct){
                for(String temp : pkBasprodTemp) {
                    finalSql = executeSql;
                    //finalSql = finalSql.replace("listsheny_pk_basprod_name",insertncProdList.getPkProdList());
                    //finalSql = finalSql.replace("",inserttestList.getPkTestList());
                    finalSql = finalSql.replace("listsheny_pk_basprod_name", ncBasprodName.getPkBasprodName());
                    finalSql = finalSql.replace("listsheny_pk_basprod_type", ncBasprodType.getPkBasprodType());
                    //finalSql = finalSql.replace("",insertncBasenType.getPkBasenType());
                    finalSql = finalSql.replace("listsheny_pk_basprod_point", point);
                    finalSql = finalSql.replace("listsheny_pk_basprod_struct", struct);
                    finalSql = finalSql.replace("listsheny_pk_basprod_contact", ncBasprodContact.getPkBasprodContact());
                    finalSql = finalSql.replace("listsheny_pk_basprod_temp", temp);
                    List<Map<String, Object>> list = customerSqlService.selectList(finalSql);
                    /*
                    if (list.size() < 1 || list.size() > 1) {
                        return baseResponse = new BaseResponse(700, "nc_sample_info取数据为空或存在多条同名称同版本数据,执行语句:" + finalSql);
                    }
                     */
                    try {
                        if (list != null) {
                            //for (Map<String,Object> map : list){
                            for(int i = 0 ; i < list.size() ; i++){
                                Map<String,Object> map = list.get(i);
                                ncSampleInfo = new NcSampleInfo();
                                pkSampleInfo.add(map.get("PK_SAMPLE_INFO").toString());
                                ncSampleInfo.setPkSampleInfo(map.get("PK_SAMPLE_INFO").toString());
                                ncSampleInfo.setPkProdType(map.get("PK_PROD_TYPE").toString());
                                ncSampleInfo.setPkBasprodName(map.get("PK_BASPROD_NAME").toString());
                                ncSampleInfo.setPkBasprodType(map.get("PK_BASPROD_TYPE").toString());
                                ncSampleInfo.setPkBasprodPoint(map.get("PK_BASPROD_POINT").toString());
                                ncSampleInfo.setPkBasprodStruct(map.get("PK_BASPROD_STRUCT").toString());
                                ncSampleInfo.setPkBasprodContact(map.get("PK_BASPROD_CONTACT").toString());
                                ncSampleInfo.setPkBasprodTemp(map.get("PK_BASPROD_TEMP").toString());
                                ncSampleInfo.setPkBasenType(map.get("PK_BASEN_TYPE").toString());
                                ncSampleInfo.setSampleInfoCode(map.get("SAMPLE_INFO_CODE").toString());
                                ncSampleInfo.setDef1(map.get("DEF1").toString());
                                ncSampleInfo.setDef2(map.get("DEF2").toString());
                                ncSampleInfo.setDef3(map.get("DEF3").toString());
                                ncSampleInfo.setDef4(map.get("DEF4").toString());
                                ncSampleInfo.setDef5(map.get("DEF5").toString());
                                ncSampleInfo.setName(map.get("NAME").toString());
                                ncSampleInfo.setcProdTypeC1(map.get("C_PROD_TYPE_C1").toString());
                                ncSampleInfo.setDescription(map.get("DESCRIPTION").toString());
                                ncSampleInfo.setEnstard(map.get("ENSTARD").toString());
                                ncSampleInfo.setTestList(map.get("TEST_LIST").toString());
                                ncSampleInfo.setSamplingPoint(map.get("SAMPLING_POINT").toString());
                                ncSampleInfo.setGrade(map.get("GRADE").toString());
                                ncSampleInfo.setcAllowedContact(map.get("C_ALLOWED_CONTACT").toString());
                                ncSampleInfo.setStage(map.get("STAGE").toString());
                                ncSampleInfo.setIsenable(BigDecimal.valueOf(Long.valueOf(map.get("ISENABLE").toString())));
                                ncSampleInfoService.insert(ncSampleInfo);
                            }
                        }
                    } catch (Exception e) {
                        return baseResponse = new BaseResponse(700, "nc_sample_info组装失败，程序中止" + e);
                    }
                }
            }
        }
        return baseResponse;
    }

    public BaseResponse checkNcBasprodTemp(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasprodTemp = new NcBasprodTemp();
        executeSql = getExecuteSql("testlist_nc_basprod_temp",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        pkBasprodTemp.clear();
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_basprod_temp取数据为空或存在多条同名称同版本数据");
        }
         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasprodTemp = new NcBasprodTemp();
                ncBasprodTemp.setPkBasprodTemp(map.get("PK_BASPROD_TEMP").toString());
                pkBasprodTemp.add(map.get("PK_BASPROD_TEMP").toString());
                ncBasprodTemp.setNcBasprodtempCode(map.get("NC_BASPRODTEMP_CODE").toString());
                ncBasprodTemp.setNcBasprodtempName(map.get("NC_BASPRODTEMP_NAME").toString());
                ncBasprodTemp.setVdef1(map.get("VDEF1").toString());
                ncBasprodTemp.setVdef2(map.get("VDEF2").toString());
                ncBasprodTemp.setVdef3(map.get("VDEF3").toString());
                ncBasprodTemp.setVdef4(map.get("VDEF4").toString());
                ncBasprodTemp.setVdef5(map.get("VDEF5").toString());
                ncBasprodTempService.insert(ncBasprodTemp);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_basprod_temp组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcBasprodContact(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasprodContact = new NcBasprodContact();
        executeSql = getExecuteSql("testlist_nc_basprod_contact",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_basprod_contact取数据为空或存在多条同名称同版本数据");
        }
         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasprodContact = new NcBasprodContact();
                ncBasprodContact.setPkBasprodContact(map.get("PK_BASPROD_CONTACT").toString());
                ncBasprodContact.setNcBasprodcontactCode(map.get("NC_BASPRODCONTACT_CODE").toString());
                ncBasprodContact.setNcBasprodcontactName(map.get("NC_BASPRODCONTACT_NAME").toString());
                ncBasprodContact.setVdef1(map.get("VDEF1").toString());
                ncBasprodContact.setVdef2(map.get("VDEF2").toString());
                ncBasprodContact.setVdef3(map.get("VDEF3").toString());
                ncBasprodContact.setVdef4(map.get("VDEF4").toString());
                ncBasprodContact.setVdef5(map.get("VDEF5").toString());
                ncBasProdContactService.insert(ncBasprodContact);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_basprod_contact组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcBasprodStruct(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasprodStruct = new NcBasprodStruct();
        executeSql = getExecuteSql("testlist_nc_basprod_struct",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        pkBasprodStruct.clear();
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_basprod_struct取数据为空或存在多条同名称同版本数据");
        }
         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasprodStruct = new NcBasprodStruct();
                ncBasprodStruct.setPkBasprodStruct(map.get("PK_BASPROD_STRUCT").toString());
                pkBasprodStruct.add(ncBasprodStruct.getPkBasprodStruct());
                ncBasprodStruct.setNcBasprodstructCode(map.get("NC_BASPRODSTRUCT_CODE").toString());
                ncBasprodStruct.setNcBasprodstructName(map.get("NC_BASPRODSTRUCT_NAME").toString());
                ncBasprodStruct.setVdef1(map.get("VDEF1").toString());
                ncBasprodStruct.setVdef2(map.get("VDEF2").toString());
                ncBasprodStruct.setVdef3(map.get("VDEF3").toString());
                ncBasprodStruct.setVdef4(map.get("VDEF4").toString());
                ncBasprodStruct.setVdef5(map.get("VDEF5").toString());
                ncBasprodStructService.insert(ncBasprodStruct);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_basprod_point组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcBasprodPoint(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasprodPoint = new NcBasprodPoint();
        executeSql = getExecuteSql("testlist_nc_basprod_point", product);
        List<Map<String, Object>> list = customerSqlService.selectList(executeSql);
        pkBasprodPoint.clear();
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_basprod_point取数据为空或存在多条同名称同版本数据");
        }
         */
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasprodPoint = new NcBasprodPoint();
                pkBasprodPoint.add(map.get("PK_BASPROD_POINT").toString());
                ncBasprodPoint.setPkBasprodPoint(map.get("PK_BASPROD_POINT").toString());
                ncBasprodPoint.setNcBasprodpointCode(map.get("NC_BASPRODPOINT_CODE").toString());
                ncBasprodPoint.setNcBasprodpointName(map.get("NC_BASPRODPOINT_NAME").toString());
                ncBasprodPoint.setVdef1(map.get("VDEF1").toString());
                ncBasprodPoint.setVdef2(map.get("VDEF2").toString());
                ncBasprodPoint.setVdef3(map.get("VDEF3").toString());
                ncBasprodPoint.setVdef4(map.get("VDEF4").toString());
                ncBasprodPoint.setVdef5(map.get("VDEF5").toString());
                ncBasprodPointService.insert(ncBasprodPoint);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_basprod_point组装失败，程序中止" + e);
        }
        return baseResponse;

    }

    public BaseResponse checkNcBasEnType(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasenType = new NcBasenType();
        executeSql = getExecuteSql("testlist_nc_basen_type",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"nc_basen_type取数据为空或存在多条同名称同版本数据");
        }

         */
        try {
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasenType = new NcBasenType();
                ncBasenType.setPkBasenType(map.get("PK_BASEN_TYPE").toString());
                ncBasenType.setPkBasprodType(ncBasprodType.getPkBasprodType().toString());
                ncBasenType.setNcBasenCode(map.get("NC_BASEN_CODE").toString());
                ncBasenType.setNcBbasenName(map.get("NC_BBASEN_NAME").toString());
                ncBasenType.setVdef1(map.get("VDEF1").toString());
                ncBasenType.setVdef2(map.get("VDEF2").toString());
                ncBasenType.setVdef3(map.get("VDEF3").toString());
                ncBasenType.setVdef4(map.get("VDEF4").toString());
                ncBasenType.setVdef5(map.get("VDEF5").toString());
                ncBasEnType.insert(ncBasenType);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"nc_basen_type组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcBasProdType(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasprodType = new NcBasprodType();
        executeSql = getExecuteSql("testlist_nc_basprod_type",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"Nc_basprod_type取数据为空或存在多条同名称同版本数据");
        }

         */
        try {
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasprodType = new NcBasprodType();
                ncBasprodType.setPkBasprodType(map.get("PK_BASPROD_TYPE").toString());
                ncBasprodType.setNcBasprodtypeCode(map.get("NC_BASPRODTYPE_CODE").toString());
                ncBasprodType.setNcBasprodtypeName(map.get("NC_BASPRODTYPE_NAME").toString());
                ncBasprodType.setVdef1(map.get("VDEF1").toString().trim());
                ncBasprodType.setVdef2(map.get("VDEF2").toString().trim());
                ncBasprodType.setVdef3(map.get("VDEF3").toString());
                ncBasprodType.setVdef4(map.get("VDEF4").toString());
                ncBasprodType.setVdef5(map.get("VDEF5").toString());
                ncBasprodTypeService.insert(ncBasprodType);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"Nc_basprod_type组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcBasProdName(Product product) {
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncBasprodName = new NcBasprodName();
        executeSql = getExecuteSql("testlist_nc_basprod_name",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        /*
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"Nc_basprod_name取数据为空或存在多条同名称同版本数据");
        }
         */
        try {
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncBasprodName = new NcBasprodName();
                ncBasprodName.setPkBasprodName(map.get("PK_BASPROD_NAME").toString());
                ncBasprodName.setNcBasprodCode(map.get("NC_BASPROD_CODE").toString());
                ncBasprodName.setNcBasprodName(map.get("NC_BASPROD_NAME").toString());
                ncBasprodName.setVdef1(map.get("VDEF1").toString());
                ncBasprodName.setVdef2(map.get("VDEF2").toString());
                ncBasprodName.setVdef3(map.get("VDEF3").toString());
                ncBasprodName.setVdef4(map.get("VDEF4").toString());
                ncBasprodName.setVdef5(map.get("VDEF5").toString());
                ncBasprodNameService.insert(ncBasprodName);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"Nc_basprod_name组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public BaseResponse checkNcTestList(Product product) {
        //检查nc_test_list表
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        ncTestList = new NcTestList();
        executeSql = getExecuteSql("testlist_nc_test_list",product);
        customerSqlService.insert(executeSql);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"Nc_Test_List取数据为空或存在多条同名称同版本数据");
        }
        try {
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                ncTestList = new NcTestList();
                ncTestList.setPkTestList(map.get("PK_TEST_LIST").toString());
                ncTestList.setName(map.get("NAME").toString());
                ncTestList.setNcTestlistCode(map.get("NC_TESTLIST_CODE").toString());
                ncTestList.setNcTestlistName(map.get("NC_TESTLIST_NAME").toString());
                ncTestList.setNcTestlistIsdisable(BigDecimal.valueOf(Long.valueOf(map.get("NC_TESTLIST_ISDISABLE").toString())));
                ncTestList.setDef1(map.get("DEF1").toString());
                ncTestList.setDef2(map.get("DEF2").toString());
                ncTestList.setDef3(map.get("DEF3").toString());
                ncTestList.setDef4(map.get("DEF4").toString());
                ncTestList.setDef5(map.get("DEF5").toString());
                String temp = customerSqlService.selectOne("select PK_TEST_LIST from nc_test_list where trim(name) = '" + ncTestList.getName().trim() + "'");
                if (temp != null){
                    customerSqlService.delete("delete from nc_test_list where PK_TEST_LIST = '" + temp + "'");
                    ncTestList.setPkTestList(temp);
                }
                ncTestListService.insert(ncTestList);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"NC_TEST_LIST组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    /**
     * 组装product组态，如果已传输，直接抛
     * @param product
     * @return
     */
    public BaseResponse checkNcProdList(Product product){
        //检查nc_prod_list语句数据是否存在
        baseResponse = new BaseResponse(StatusCode.SUCCESS);
        executeSql = getExecuteSql("testlist_nc_prod_list",product);
        List<Map<String,Object>> list =  customerSqlService.selectList(executeSql);
        if (list.size() < 1 || list.size() > 1){
            return baseResponse = new BaseResponse(700,"NC_PROD_LIST取数据为空或存在多条同名称同版本数据");
        }
        try{
            //for (Map<String,Object> map : list){
            for(int i = 0 ; i < list.size() ; i++){
                Map<String,Object> map = list.get(i);
                //logger.info(map.get("PK_PROD_LIST").toString());
                System.out.print(map.get("PK_PROD_LIST").toString());
                ncProdList = new NcProdList();
                ncProdList.setPkProdList(map.get("PK_PROD_LIST").toString());
                ncProdList.setName(map.get("NAME").toString());
                ncProdList.setVersion(Long.valueOf(map.get("VERSION").toString()));
                ncProdList.setNcProdCode(map.get("NC_PROD_CODE").toString());
                ncProdList.setNcProdName(map.get("NC_PROD_NAME").toString());
                ncProdList.setNcProdIsdisable(BigDecimal.valueOf(Long.valueOf(map.get("NC_PROD_ISDISABLE").toString())));
                ncProdList.setDef1(map.get("DEF1").toString());
                ncProdList.setDef2(map.get("DEF2").toString());
                ncProdList.setDef3(map.get("DEF3").toString());
                ncProdList.setDef4(map.get("DEF4").toString());
                ncProdList.setDef5(map.get("DEF5").toString());
                ncProdList.setNcProdDes(map.get("NC_PROD_DES").toString());
                ncProdList.setNcProdAlias(map.get("NC_PROD_ALIAS").toString());
                int k = ncProdListService.insert(ncProdList);
                System.out.println("k = " +  k);
            }
        }catch (Exception e){
            return baseResponse = new BaseResponse(700,"NC_PROD_LIST组装失败，程序中止" + e);
        }
        return baseResponse;
    }

    public Boolean checkNcProdListExist(Product product){
        //判断nc_prod_list中是否已经存在该product，返回true为存在，返回false为不存在需要同步
        //ncProdListKey = new NcProdListKey();
        //ncProdListKey.setName(product.getName());
        //ncProdListKey.setVersion(product.getVersion());
        //ncProdList = new NcProdList();
        //ncProdList = ncProdListService.selectByPrimaryKey(ncProdListKey);
        List<Map<String, Object>> l = customerSqlService.selectList("select * from nc_prod_list where name = '" + product.getName() + "' and version = " + product.getVersion());
        if (l.size() > 0){
            return true;
        }else {
            return false;
        }
    }

    public String getExecuteSql(String modules,Product product){
        //获取sql语句
        String sql = "";
        try{
            logger.info("开始获取模块语句,module:{}..............",modules);
            sql = customerSqlService.selectOne("select sql_text from sql_records where sql_code = '" + modules + "'");
            //语句替换
            /**
             * sheny : product.name
             * why   : product.version
             * shenycode : product.code
             * shenytestlist : product.testlist
             */
            sql = sql.replace("sheny",product.getName());
            sql = sql.replace("why",String.valueOf(product.getVersion()));
            sql = sql.replace("ccode",product.getCode());
            sql = sql.replace("ttestlist",product.getTestList());
            logger.info("结束获取模块语句,module:{}..............",modules);
        }catch (Exception e){
            logger.error("获取语句出错,modules:{},cause:{}",modules,e.getStackTrace());
        }
        return sql;
    }


    public int test(){
        NcProdList ncProdList1 = new NcProdList();
        ncProdList1.setPkProdList("sheny");
        ncProdList1.setNcProdAlias("sheny");
        ncProdList1.setNcProdCode("sheny");
        ncProdList1.setNcProdDes("sheny");
        ncProdList1.setNcProdIsdisable(BigDecimal.ONE);
        ncProdList1.setNcProdName("sheny");
        ncProdList1.setName("sheny");
        ncProdList1.setVersion((long) 1);
        int i = 0;
        try{
           i =  ncProdListService.insert(ncProdList1);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println(i);
        return i;
    }


}
